package zhibi.wechat.mp.config.wx_cp.handler;

import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import zhibi.utils.JSONUtils;
import zhibi.wechat.mp.domain.Msg;
import zhibi.wechat.mp.service.MsgService;

import java.util.Map;


/**
 * 记录消息
 */
@Component
public class LogHandler extends AbstractHandler {

    @Autowired
    private MsgService msgService;

    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
                                    Map<String, Object> context, WxMpService wxMpService,
                                    WxSessionManager sessionManager) {
        this.logger.info("\n接收到请求消息，内容：{}", JSONUtils.objToJson(wxMessage));
        Msg msg = new Msg();
        BeanUtils.copyProperties(wxMessage, msg);
        msgService.insertSelective(msg);
        return null;
    }

}
